package service;

import dao.PetDao;
import dao.PetDaoMySQLImpl;
import dao.PetDaoOracleImpl;
import entity.Pet;
import factory.PetDaoFactory;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("petService")
public class PetServiceImpl implements PetService{
//    PetDao petDao = new PetDaoMySQLImpl();
    //通过指定的名称获取Pet实例
    //PetDao petDao = PetDaoFactory.getInstance(PetDaoFactory.defaultBeanName);

    //@Resource(name = "petDaoMySQL")
    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;
    //@Autowired
    //@Qualifier("petDaoMySQL")
    public PetDao getPetDao(){return petDao;}
    public void setPetDao(PetDao petDao) {this.petDao = petDao;}
    @Override
    public boolean save(Pet pet) {
        int rows = petDao.insert(pet);
        delay(3000);
        return rows>0;
    }

    private void delay(int time) {
        try{
            Thread.sleep(time);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    @Override
    public boolean modify(Pet pet) {
        delay(2000);
        return false;
    }

    @Override
    public boolean del(Integer id) {
        delay(1000);
        return false;
    }
}
